package redis.client.nedis;

import java.io.Serializable;

/**
 * @author gaodong
 */
public class HostAndPort implements Serializable {
    private String host;
    private int port;

    public HostAndPort(String host, int port) {
        this.host = host;
        this.port = port;
    }

    public String getHost() {
        return host;
    }

    public int getPort() {
        return port;
    }

    @Override
    public int hashCode() {
        return 31 * host.hashCode() + port;
    }

    @Override
    public String toString() {
        return host + ":" + port;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj == this) {
            return true;
        }
        if (!(obj instanceof HostAndPort)) {
            return false;
        }

        HostAndPort hp = (HostAndPort) obj;

        String thisHost = host;
        String hpHost = hp.host;
        return port == hp.port && thisHost.equals(hpHost);
    }

    public static HostAndPort build(String host, int port) {
        return new HostAndPort(host, port);
    }
}
